
const _loader = Symbol('_loader');
const _error = Symbol('_error');
const _callBack = Symbol('_callBack');
let instance = true;
export default class UtilsLoader {
    constructor(_type, _data, _url, _that, callback) {
        this.type = _type;
        this.data = _data;
        this.url = _url;
        this.callback = callback;
        _that ? _that : this[_error]('no this?');
        this.url ? _that.load.setBaseURL(this.url) : this[_error]('no url?');
        this.type ? this[_loader](this.type, _that) : this[_error]('no type?');
    }

    [_loader](_type, _that) {
        switch (_type) {
            case 'image':
                if (!this.data) return this[_error]('no data?');
                this.data.forEach(element => {
                    _that.load.image(element.key, element.path);
                });
                this[_callBack](_that);
                break;
            case 'atlas':
                if (!this.data) return this[_error]('no data?');
                this.data.forEach(element => {
                    _that.load.atlas(element.key, element.imagePath, element.jsonPath);
                });
                this[_callBack](_that);
                break
            case 'spine':
                if (!this.data) return this[_error]('no data?');
                this.data.forEach(element => {
                    _that.load.spine(element.key, element.jsonPath, element.atlasPath, element.anima);
                });
                this[_callBack](_that);
                break;
        }
    }

    [_error](err) {
        throw err;
    }

    [_callBack](_that) {
        if (instance) {
            _that.load.on('progress', num => {
                this.callback('资源加载进度:' + num);
            })
            instance = false;
        }
    }
}